package com.ruoyi.wgjlcData.service.impl;

import com.alibaba.fastjson2.JSON;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.wgjlcData.domain.plat.DataWgjlcYlbh;
import com.ruoyi.wgjlcData.domain.vo.TestOneData;
import com.ruoyi.wgjlcData.mapper.DataWgjlcYlbhMapper;
import com.ruoyi.wgjlcData.service.IDataWgjlcYlbhService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.concurrent.Future;


/**
 * 无轨胶轮车压力保护Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-02-27
 */
@Service
public class DataWgjlcYlbhServiceImpl implements IDataWgjlcYlbhService
{
    @Autowired
    private DataWgjlcYlbhMapper dataWgjlcYlbhMapper;

    /**
     * 查询无轨胶轮车压力保护
     * 
     * @param ylbhId 无轨胶轮车压力保护主键
     * @return 无轨胶轮车压力保护
     */
    @Override
    public DataWgjlcYlbh selectDataWgjlcYlbhByYlbhId(Long ylbhId)
    {
        return dataWgjlcYlbhMapper.selectDataWgjlcYlbhByYlbhId(ylbhId);
    }

    /**
     * 查询无轨胶轮车压力保护列表
     * 
     * @param dataWgjlcYlbh 无轨胶轮车压力保护
     * @return 无轨胶轮车压力保护
     */
    @Override
    public List<DataWgjlcYlbh> selectDataWgjlcYlbhList(DataWgjlcYlbh dataWgjlcYlbh)
    {
        return dataWgjlcYlbhMapper.selectDataWgjlcYlbhList(dataWgjlcYlbh);
    }

    /**
     * 新增无轨胶轮车压力保护
     * 
     * @param dataWgjlcYlbh 无轨胶轮车压力保护
     * @return 结果
     */
    @Override
    public int insertDataWgjlcYlbh(DataWgjlcYlbh dataWgjlcYlbh)
    {
        dataWgjlcYlbh.setCreateTime(DateUtils.getNowDate());
        return dataWgjlcYlbhMapper.insertDataWgjlcYlbh(dataWgjlcYlbh);
    }

    /**
     * 修改无轨胶轮车压力保护
     * 
     * @param dataWgjlcYlbh 无轨胶轮车压力保护
     * @return 结果
     */
    @Override
    public int updateDataWgjlcYlbh(DataWgjlcYlbh dataWgjlcYlbh)
    {
        dataWgjlcYlbh.setUpdateTime(DateUtils.getNowDate());
        //list转Json字符串
        if(!dataWgjlcYlbh.getTestOneDataList().isEmpty()) {
            dataWgjlcYlbh.setDataList(JSON.toJSONString(dataWgjlcYlbh.getTestOneDataList()));
        }
        return dataWgjlcYlbhMapper.updateDataWgjlcYlbh(dataWgjlcYlbh);
    }

    /**
     * 查询无轨胶轮车-压力保护
     *
     * @param dataTaskId
     * @return 无轨胶轮车-压力保护
     */
    @Async("threadPoolKy")
    @Override
    public Future<List<DataWgjlcYlbh>> selectDataWgjlcYlbhByDataTaskId(Long dataTaskId) {
        List<DataWgjlcYlbh> dataWgjlcYlbhEntities = dataWgjlcYlbhMapper.selectDataWgjlcYlbhByDataTaskId(dataTaskId);
        if (dataWgjlcYlbhEntities.size() != 0) {
            dataWgjlcYlbhEntities.forEach(item -> {
                if (item.getDataList() != null && item.getDataList().length() != 0) {
                    item.setTestOneDataList(JSON.parseArray(item.getDataList(), TestOneData.class));
                    item.setListSize(item.getTestOneDataList().size());
                }
            });
        }
        return new AsyncResult<>(dataWgjlcYlbhEntities);
    }

    /**
     * 修改状态为2
     *
     * @param dataTaskId
     */
    @Override
    public int updateDataWgjlcYlbhByDataTaskId(Long dataTaskId) {
        return dataWgjlcYlbhMapper.updateDataWgjlcYlbhByDataTaskId(dataTaskId);
    }

    /**
     * 批量新增无轨胶轮车-压力保护
     *
     * @param dataWgjlcYlbh 无轨胶轮车-压力保护
     * @return 结果
     */
    @Override
    public int batchDataWgjlcYlbh(List<DataWgjlcYlbh> dataWgjlcYlbh) {
        return dataWgjlcYlbhMapper.batchDataWgjlcYlbh(dataWgjlcYlbh);
    }

    /**
     * 批量删除无轨胶轮车压力保护
     * 
     * @param ylbhIds 需要删除的无轨胶轮车压力保护主键
     * @return 结果
     */
    @Override
    public int deleteDataWgjlcYlbhByYlbhIds(Long[] ylbhIds)
    {
        return dataWgjlcYlbhMapper.deleteDataWgjlcYlbhByYlbhIds(ylbhIds);
    }

    /**
     * 删除无轨胶轮车压力保护信息
     * 
     * @param ylbhId 无轨胶轮车压力保护主键
     * @return 结果
     */
    @Override
    public int deleteDataWgjlcYlbhByYlbhId(Long ylbhId)
    {
        return dataWgjlcYlbhMapper.deleteDataWgjlcYlbhByYlbhId(ylbhId);
    }
}
